package com.common.redis;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import com.constants.CacheKey;

@Component
public class RedisClientImpl implements RedisClient {

    private ValueOperations<String, String> valueOps;
    private String split = "_";

    @Autowired
    public RedisClientImpl(ValueOperations<String, String> valueOps) {
        this.valueOps = valueOps;
    }

    @Override
    public void save(String value, long timeout, CacheKey cacheKey, String prefix) {
        String key = cacheKey.name() + split + prefix;
        valueOps.set(key, value, timeout, TimeUnit.MINUTES);
    }

    @Override
    public String get(CacheKey cacheKey, String prefix) {
        String key = cacheKey.name() + split + prefix;
        return valueOps.get(key);
    }

}
